package com.softeem.blog.dao;

import java.util.List;

import com.softeem.blog.entity.Comment;
import com.softeem.blog.utils.DBUtils;

public class CommentDAO implements IBaseDAO<Comment>{

	@Override
	public boolean insert(Comment t) {
		String sql = "insert into comment(cname,email,content,cip,pid) values(?,?,?,?,?)";
		return DBUtils.exeUpdate(sql, t.getCname(),t.getEmail(),t.getContent(),t.getCip(),t.getPid()); 
	}

	@Override
	public boolean deleteById(int id) {
		String sql = "delete from comment where id=?";
		return DBUtils.exeUpdate(sql, id);
	}

	@Override
	public boolean update(Comment t) {
		return false;
	}

	@Override
	public Comment findById(int id) {
		String sql = "select * from comment where id=?";
		return DBUtils.queryOne(Comment.class, sql, id);
	}

	@Override
	public List<Comment> findByPage(int pageSize, int pageNow) {
		String sql = "select * from comment limit ?,?";
		return DBUtils.queryList(Comment.class, sql, (pageNow-1)*pageSize,pageSize);
	}

	@Override
	public int getCount() {
		String sql = "select count(*) from comment";
		return DBUtils.queryCount(sql);
	}

}
